package com.ruoyi.asms.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.ams.controller.*;
import com.ruoyi.asms.domain.*;
import com.ruoyi.asms.domain.vo.*;
import com.ruoyi.asms.service.*;
import com.ruoyi.asms.service.AsmsReusingService;
import com.ruoyi.common.core.domain.AsmsAssetFullInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.SysGeographical;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.*;
import com.ruoyi.common.core.domain.statistics.vo.HistogramVo;
import com.ruoyi.common.core.domain.statistics.vo.LineChartVo;
import com.ruoyi.common.core.domain.statistics.vo.PieChartVo;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.security.annotation.PreAuthorize;
import com.ruoyi.security.service.TokensService;
import com.ruoyi.system.controller.SysDeptController;
import com.ruoyi.system.controller.SysGeographicalController;
import com.ruoyi.system.controller.SysUserController;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * 售后维护模块数据统计Controller
 * @author WJH
 * @date 2021-12-15
 */
@RestController
@RequestMapping("/asms/AsmsDataStatistics")
public class AsmsDataStatisticsController extends BaseController {

    @Autowired
    private TokensService tokenService;
    @Autowired
    private IAsmsAssetFullInfoService assetFullInfoService;
    @Autowired
    private IAsmsFaultResolveStageService faultResolveStageService;
    @Autowired
    private AsmsReusingService asmsReusingService;
//    @Autowired
//    private RemoteAssetAddressService remoteAssetAddressService;
//    @Autowired
//    private RemoteAssetBrandService remoteAssetBrandService;
//    @Autowired
//    private RemoteAssetProjectService remoteAssetProjectService;
//    @Autowired
//    private RemoteAssetTypeService remoteAssetTypeService;
    @Autowired
    private IAsmsFaultAssetReasonService faultAssetReasonService;
//    @Autowired
//    private RemoteAssetTemplateService remoteAssetTemplateService;
//    @Autowired
//    private RemoteDeptService remoteDeptService;
//    @Autowired
//    private RemoteUserService remoteUserService;
    @Autowired
    private IAsmsOwnMaintenanceDeptService ownMaintenanceDeptService;
    @Autowired
    private IAsmsFaultReportStageService faultReportStageService;
    @Autowired
    private IAsmsFaultDispatchStageService faultDispatchStageService;
    @Autowired
    private IAsmsFaultConfirmStageService faultConfirmStageService;
    @Autowired
    private IInspectionService inspectionService;
    @Autowired
    private IInspectionTaskService inspectionTaskService;
    @Autowired
    private IAsmsFaultAssetService asmsFaultAssetService;
//    @Autowired
//    private RemoteGeographicalService remoteGeographicalService;
    @Autowired
    private IAsmsDataStatisticsService asmsDataStatisticsService;
    @Autowired
    private AmsOwnAddressController ownAddressController;
    @Autowired
    private AmsAssetTypeController assetTypeController;
    @Autowired
    private AmsAssetTemplateController assetTemplateController;
    @Autowired
    private AmsAssetBrandController assetBrandController;
    @Autowired
    private AmsAssetProjectController assetProjectController;
    @Autowired
    private SysDeptController deptController;
    @Autowired
    private SysUserController userController;
    @Autowired
    private SysGeographicalController geographicalController;

    @PreAuthorize
    @ApiOperation("当前部门维护的资产数量")
    @GetMapping("/getMyDeptMAssetNum")
    public AjaxResult getMyDeptMAssetNum(@RequestParam(value = "startTime", required = false) Long startTime,
                                         @RequestParam(value = "endTime", required = false) Long endTime) {
        Long deptId = tokenService.getLoginUser().getDeptid();
        QueryWrapper<AsmsAssetFullInfo> wrapper = new QueryWrapper<>();
        wrapper.eq(AsmsAssetFullInfo.MAINTENANCE_DEPT_ID, deptId);
        if (startTime != null && endTime != null) {
            wrapper.ge(AsmsAssetFullInfo.CREATE_TIME, startTime).le(AsmsAssetFullInfo.CREATE_TIME, endTime);
        }
        long count = assetFullInfoService.count(wrapper);
        return AjaxResult.success(count);
    }

    @PreAuthorize
    @ApiOperation("当前部门累计解决的故障数量")
    @GetMapping("/getMyDeptSolveFaultNum")
    public AjaxResult getMyDeptSolveFaultNum(@RequestParam(value = "startTime", required = false) Long startTime,
                                             @RequestParam(value = "endTime", required = false) Long endTime) {
        Long deptId = tokenService.getLoginUser().getDeptid();
        QueryWrapper<AsmsFaultResolveStage> wrapper = new QueryWrapper<>();
        wrapper.eq(AsmsFaultResolveStage.MAINTENANCE_DEPT_ID, deptId).eq(AsmsFaultResolveStage.STATUS, 1);
        if (startTime != null && endTime != null) {
            wrapper.ge(AsmsFaultResolveStage.END_TIME, startTime).le(AsmsFaultResolveStage.END_TIME, endTime);
        }
        long count = faultResolveStageService.count(wrapper);
        return AjaxResult.success(count);
    }

    @PreAuthorize
    @ApiOperation("区域故障数量")
    @GetMapping("/getFaultNumWithAddress")
    public R<List<PieChartVo>> getFaultNumWithAddress(@RequestParam(value = "startTime", required = false) Long startTime,
                                                      @RequestParam(value = "endTime", required = false) Long endTime) {
        ArrayList<PieChartVo> pieChartVos = new ArrayList<>();
        List<FaultInfoView> faultList = asmsReusingService.getUserCanLookFaultList(startTime, endTime);
        if (faultList.size() == 0) {
            return R.ok(pieChartVos);
        }
        R<List<AmsOwnAddress>> addressList = ownAddressController.getAddressList();
        if (addressList.getCode() == R.FAIL) {
            throw new ServiceException(addressList.getMsg());
        }
        for (AmsOwnAddress address : addressList.getData()) {
            int faultNum = 0;
            for (FaultInfoView faultInfoView : faultList) {
                if (faultInfoView.getAddressId() != null && faultInfoView.getAddressId().equals(address.getAddressId())) {
                    faultNum ++;
                }
            }
            if (faultNum > 0) {
                PieChartVo pieChartVo = new PieChartVo();
                pieChartVo.setType(address.getFullName());
                pieChartVo.setValue(faultNum);
                pieChartVos.add(pieChartVo);
            }
        }
        pieChartVos.sort(Comparator.comparing(PieChartVo::getValue).reversed());
        return R.ok(pieChartVos);
    }

    @PreAuthorize
    @ApiOperation("资产类型故障图")
    @GetMapping("/getFaultNumWithType")
    public R<List<HistogramVo>> getFaultNumWithType(@RequestParam(value = "startTime", required = false) Long startTime,
                                                    @RequestParam(value = "endTime", required = false) Long endTime) {
        ArrayList<HistogramVo> histogramVos = new ArrayList<>();
        List<FaultInfoView> faultList = asmsReusingService.getUserCanLookFaultList(startTime, endTime);
        if (faultList.size() == 0) {
            return R.ok(histogramVos);
        }
        //只查询故障资产中出现的类型
        HashSet<Long> typeIds = new HashSet<>();
        faultList.forEach(item -> typeIds.add(item.getAssetTypeId()));
        R<Map<Long, AmsAssetType>> typeList = assetTypeController
                .getAddressByIds(typeIds.toArray(new Long[0]));
        if (typeList.getCode() == R.FAIL) {
            throw new ServiceException(typeList.getMsg());
        }
        for (Map.Entry<Long, AmsAssetType> typeEntry : typeList.getData().entrySet()) {
            int faultNum = 0;
            for (FaultInfoView infoView : faultList) {
                if (infoView.getAssetTypeId().equals(typeEntry.getKey())) {
                    faultNum ++;
                }
            }
            if (faultNum > 0) {
                HistogramVo histogramVo = new HistogramVo();
                histogramVo.setParent(typeEntry.getValue().getAssetTypeName());
                histogramVo.setValue(faultNum);
                histogramVo.setId(typeEntry.getKey());
                histogramVos.add(histogramVo);
            }
        }
        histogramVos.sort(Comparator.comparing(HistogramVo::getValue).reversed());
        return R.ok(histogramVos);
    }

    @PreAuthorize
    @ApiOperation("资产故障原因（选择了资产类型后）故障统计图")
    @GetMapping("/getFaultNumWithReason")
    public R<List<HistogramVo>> getFaultNumWithReason(@ApiParam("选中的资产类型的id") @RequestParam("typeId") Long typeId,
                                                      @RequestParam(value = "startTime", required = false) Long startTime,
                                                      @RequestParam(value = "endTime", required = false) Long endTime) {
        ArrayList<HistogramVo> histogramVos = new ArrayList<>();
        HashSet<Long> faultAssetIds = new HashSet<>();
        List<FaultInfoView> faultList = asmsReusingService.getUserCanLookFaultList(startTime, endTime);
        if (faultList.size() == 0) {
            return R.ok(histogramVos);
        }
        faultList.forEach(item -> faultAssetIds.add(item.getFaultAssetId()));
        //获取用户可见的在处理阶段的故障资产
        List<AsmsFaultResolveStage> list = faultResolveStageService.list(new QueryWrapper<AsmsFaultResolveStage>()
                .in(AsmsFaultResolveStage.FAULT_ASSET_ID, faultAssetIds));
        //获取类型对应的故障原因列表
        List<AsmsFaultAssetReason> reasonList = faultAssetReasonService.list(new QueryWrapper<AsmsFaultAssetReason>()
                .eq(AsmsFaultAssetReason.ASSET_TYPE_ID, typeId));
        for (AsmsFaultAssetReason reason : reasonList) {
            int faultNum = 0;
            for (AsmsFaultResolveStage resolveStage : list) {
                if (resolveStage.getAssetFaultReasonId() != null &&
                        resolveStage.getAssetFaultReasonId().equals(reason.getFaultAssetReasonId())) {
                    faultNum ++;
                }
            }
            if (faultNum > 0) {
                HistogramVo histogramVo = new HistogramVo();
                histogramVo.setParent(reason.getFaultReason());
                histogramVo.setValue(faultNum);
                histogramVos.add(histogramVo);
            }
        }
        histogramVos.sort(Comparator.comparing(HistogramVo::getValue).reversed());
        return R.ok(histogramVos);
    }

    @PreAuthorize
    @ApiOperation("资产型号（选择了资产类型后）故障统计图")
    @GetMapping("/getFaultNumWithTemplate")
    public R<List<HistogramVo>> getFaultNumWithTemplate(@ApiParam("选中的资产类型的id") @RequestParam("typeId") Long typeId,
                                                        @RequestParam(value = "startTime", required = false) Long startTime,
                                                        @RequestParam(value = "endTime", required = false) Long endTime) {
        ArrayList<HistogramVo> histogramVos = new ArrayList<>();
        List<FaultInfoView> faultList = asmsReusingService.getUserCanLookFaultList(startTime, endTime);
        if (faultList.size() == 0) {
            return R.ok(histogramVos);
        }
        R<List<AmsAssetTemplate>> list = assetTemplateController.getListByTypeId(typeId);
        if (list.getCode() == R.FAIL) {
            throw new ServiceException(list.getMsg());
        }
        if (list.getData().size() == 0) {
            return R.ok(histogramVos);
        }
        for (AmsAssetTemplate template : list.getData()) {
            int faultNum = 0;
            for (FaultInfoView infoView : faultList) {
                if (infoView.getAssetTemplateId() != null &&
                        infoView.getAssetTemplateId().equals(template.getAssetTemplateId())) {
                    faultNum ++;
                }
            }
            if (faultNum > 0) {
                HistogramVo histogramVo = new HistogramVo();
                histogramVo.setParent(template.getAssetTemplateName());
                histogramVo.setValue(faultNum);
                histogramVos.add(histogramVo);
            }
        }
        histogramVos.sort(Comparator.comparing(HistogramVo::getValue).reversed());
        return R.ok(histogramVos);
    }

    @PreAuthorize
    @ApiOperation("品牌故障图")
    @GetMapping("/getFaultNumWithBrand")
    public R<List<PieChartVo>> getFaultNumWithBrand(@RequestParam(value = "startTime", required = false) Long startTime,
                                                    @RequestParam(value = "endTime", required = false) Long endTime) {
        ArrayList<PieChartVo> pieChartVos = new ArrayList<>();
        List<FaultInfoView> userCanLookFaultList = asmsReusingService.getUserCanLookFaultList(startTime, endTime);
        if (userCanLookFaultList.size() == 0) {
            return R.ok(pieChartVos);
        }
        R<List<AmsAssetBrand>> assetBrandList =
                assetBrandController.getAssetBrandList();
        if (assetBrandList.getCode() == R.FAIL) {
            throw new ServiceException(assetBrandList.getMsg());
        }
        for (AmsAssetBrand assetBrand : assetBrandList.getData()) {
            int faultNum = 0;
            for (FaultInfoView faultInfoView : userCanLookFaultList) {
                if (faultInfoView.getBrandId() != null &&
                        faultInfoView.getBrandId().equals(assetBrand.getBrandId())) {
                    faultNum ++;
                }
            }
            if (faultNum > 0) {
                PieChartVo pieChartVo = new PieChartVo();
                pieChartVo.setType(assetBrand.getBrandName());
                pieChartVo.setValue(faultNum);
                pieChartVos.add(pieChartVo);
            }
        }
        pieChartVos.sort(Comparator.comparing(PieChartVo::getValue).reversed());
        return R.ok(pieChartVos);
    }

    @PreAuthorize
    @ApiOperation("批次故障图")
    @GetMapping("/getFaultNumWithProject")
    public R<List<PieChartVo>> getFaultNumWithProject(@RequestParam(value = "startTime", required = false) Long startTime,
                                                      @RequestParam(value = "endTime", required = false) Long endTime) {
        ArrayList<PieChartVo> pieChartVos = new ArrayList<>();
        List<FaultInfoView> list = asmsReusingService.getUserCanLookFaultList(startTime, endTime);
        if (list.size() == 0) {
            return R.ok(pieChartVos);
        }
        R<List<AmsAssetProject>> projectList = assetProjectController.getProjectList();
        if (projectList.getCode() == R.FAIL) {
            throw new ServiceException(projectList.getMsg());
        }
        for (AmsAssetProject project : projectList.getData()) {
            int faultNum = 0;
            for (FaultInfoView infoView : list) {
                if (infoView.getProjectId() != null && infoView.getProjectId().equals(project.getProjectId())) {
                    faultNum ++;
                }
            }
            if (faultNum > 0) {
                PieChartVo pieChartVo = new PieChartVo();
                pieChartVo.setType(project.getProjectName());
                pieChartVo.setValue(faultNum);
                pieChartVos.add(pieChartVo);
            }
        }
        pieChartVos.sort(Comparator.comparing(PieChartVo::getValue).reversed());
        return R.ok(pieChartVos);
    }

    @PreAuthorize
    @ApiOperation("维护部门处理故障统计图")
    @GetMapping("/getFaultNumWithMDept")
    public R<List<HistogramVo>> getFaultNumWithMDept(@ApiParam("选中的部门的id") @RequestParam("deptId") Long deptId,
                                                     @RequestParam(value = "startTime", required = false) Long startTime,
                                                     @RequestParam(value = "endTime", required = false) Long endTime) {
        ArrayList<HistogramVo> histogramVos = new ArrayList<>();
        List<FaultInfoView> faultList = asmsReusingService.getUserCanLookFaultList(startTime, endTime);
        if (faultList.size() == 0) {
            return R.ok(histogramVos);
        }

        //计算某个部门的所有下级的故障处理量
        R<List<SysDept>> allNextLevelDeptList =  deptController.getAllNextLevelDeptList(deptId);
        if (allNextLevelDeptList.getCode() == R.FAIL) {
            throw new ServiceException(allNextLevelDeptList.getMsg());
        }
        int faultResolveNum = 0;
        for (SysDept sysDept : allNextLevelDeptList.getData()) {
            for (FaultInfoView infoView : faultList) {
                if (infoView.getMaintenanceDeptId() != null && infoView.getIsFinish().equals(0)
                        && infoView.getMaintenanceDeptId().equals(sysDept.getDeptId())) {
                    faultResolveNum ++;
                }
            }
        }

        R<List<SysDept>> deptList =  deptController.getDeptAndNextLevelDeptList(deptId);
        if (deptList.getCode() == R.FAIL) {
            throw new ServiceException(deptList.getMsg());
        }
        for (SysDept dept : deptList.getData()) {
            int faultNum = 0;
            for (FaultInfoView view : faultList) {
                if (view.getMaintenanceDeptId() != null && view.getIsFinish().equals(0) &&
                        view.getMaintenanceDeptId().equals(dept.getDeptId())) {
                    faultNum ++;
                }
            }
            if (faultNum > 0) {
                HistogramVo histogramVo = new HistogramVo();
                histogramVo.setParent(dept.getDeptShortName());
                histogramVo.setValue(faultNum);
                if (dept.getDeptId().equals(deptId)) {
                    histogramVo.setValue(faultNum + faultResolveNum);
                }
                histogramVos.add(histogramVo);
            }
        }
        histogramVos.sort(Comparator.comparing(HistogramVo::getValue).reversed());
        return R.ok(histogramVos);
    }

    @PreAuthorize
    @ApiOperation("维修人（选择维护部门后）故障处理统计图")
    @GetMapping("/getFaultNumWithMPeople")
    public R<List<HistogramVo>> getFaultNumWithMPeople(@ApiParam("选中的部门的id") @RequestParam("deptId") Long deptId,
                                                       @RequestParam(value = "startTime", required = false) Long startTime,
                                                       @RequestParam(value = "endTime", required = false) Long endTime) {
        ArrayList<HistogramVo> histogramVos = new ArrayList<>();
        List<FaultInfoView> userCanLookFaultList = asmsReusingService.getUserCanLookFaultList(startTime, endTime);
        if (userCanLookFaultList.size() == 0) {
            R.ok(histogramVos);
        }

        R<List<SysUser>> userList =  userController.getMUserByDeptId(deptId);
        if (userList.getCode() == R.FAIL) {
            throw new ServiceException(userList.getMsg());
        }
        for (SysUser user : userList.getData()) {
            int faultNum = 0;
            for (FaultInfoView infoView : userCanLookFaultList) {
                if (infoView.getFaultResolveUserId() != null &&
                        infoView.getFaultResolveUserId().equals(user.getUserId())) {
                    faultNum ++;
                }
            }
            if (faultNum > 0) {
                HistogramVo histogramVo = new HistogramVo();
                histogramVo.setParent(user.getNickName());
                histogramVo.setValue(faultNum);
                histogramVos.add(histogramVo);
            }
        }
        histogramVos.sort(Comparator.comparing(HistogramVo::getValue).reversed());
        return R.ok(histogramVos);
    }

    @PreAuthorize
    @ApiOperation("维护客户故障统计图")
    @GetMapping("/getFaultNumWithODept")
    public R<List<HistogramVo>> getFaultNumWithODept(@RequestParam(value = "oDeptId", required = false) Long oDeptId,
                                                     @RequestParam(value = "startTime", required = false) Long startTime,
                                                     @RequestParam(value = "endTime", required = false) Long endTime) {
        List<FaultInfoView> userCanLookFaultList = asmsReusingService.getUserCanLookFaultList(startTime, endTime);
        ArrayList<HistogramVo> histogramVos = new ArrayList<>();
        if (userCanLookFaultList.size() == 0) {
            return R.ok(histogramVos);
        }

        //获取当前维护部门的客户列表
        HashSet<Long> oDeptIds = new HashSet<>();
        Long deptId = tokenService.getLoginUser().getDeptid();
        List<AsmsOwnMaintenanceDept> list = ownMaintenanceDeptService.list(new QueryWrapper<AsmsOwnMaintenanceDept>()
                .eq(AsmsOwnMaintenanceDept.MAINTENANCE_DEPT_ID, deptId));
        if (oDeptId == null) {
            if (list.size() != 0) {
                list.forEach(item -> oDeptIds.add(item.getOwnDeptId()));
            }
        } else {
            oDeptIds.add(oDeptId);
        }
        R<List<SysDept>> oDeptList = deptController.getDeptListByIds(oDeptIds);
        if (oDeptList.getCode() == R.FAIL) {
            throw new ServiceException(oDeptList.getMsg());
        }
        for (SysDept sysDept : oDeptList.getData()) {
            int faultNum = 0;
            for (FaultInfoView infoView : userCanLookFaultList) {
                if (infoView.getOwnDeptId() != null && infoView.getOwnDeptId().equals(sysDept.getDeptId())) {
                    faultNum ++;
                }
            }
            if (faultNum > 0) {
                HistogramVo histogramVo = new HistogramVo();
                histogramVo.setParent(sysDept.getDeptShortName());
                histogramVo.setValue(faultNum);
                histogramVos.add(histogramVo);
            }
        }
        histogramVos.sort(Comparator.comparing(HistogramVo::getValue).reversed());
        return R.ok(histogramVos);
    }

    @PreAuthorize
    @ApiOperation("故障报修阶段统计图")
    @GetMapping("/getFaultNumOnReportStage")
    public R<List<LineChartVo>> getFaultNumOnReportStage(@RequestParam(value = "startTime", required = false) Long startTime,
                                                         @RequestParam(value = "endTime", required = false) Long endTime) {
        ArrayList<LineChartVo> lineChartVos = new ArrayList<>();
        List<FaultInfoView> list = asmsReusingService.getUserCanLookFaultList(startTime, endTime);
        if (list.size() == 0)
            return R.ok(lineChartVos);
        HashSet<Long> faultAssetIds = new HashSet<>();
        list.forEach(item -> faultAssetIds.add(item.getFaultAssetId()));
        List<AsmsFaultReportStage> reportStages = faultReportStageService.list(new QueryWrapper<AsmsFaultReportStage>()
                .in(AsmsFaultReportStage.FAULT_ASSET_ID, faultAssetIds).orderByDesc(AsmsFaultReportStage.START_TIME));
        for (AsmsFaultReportStage reportStage : reportStages) {
            LineChartVo lineChartVo = new LineChartVo();
            Long time = (reportStage.getEndTime() - reportStage.getStartTime());
            lineChartVo.setTitle("故障" + reportStage.getFaultAssetId());
            lineChartVo.setValue(time);
            lineChartVos.add(lineChartVo);
        }
        return R.ok(lineChartVos);
    }

    @PreAuthorize
    @ApiOperation("故障派单阶段统计图")
    @GetMapping("/getFaultNumOnDispatchStage")
    public R<List<LineChartVo>> getFaultNumOnDispatchStage(@RequestParam(value = "startTime", required = false) Long startTime,
                                                           @RequestParam(value = "endTime", required = false) Long endTime) {
        List<FaultInfoView> userCanLookFaultList = asmsReusingService.getUserCanLookFaultList(startTime, endTime);
        ArrayList<LineChartVo> lineChartVos = new ArrayList<>();
        if (userCanLookFaultList.size() == 0) {
            return R.ok(lineChartVos);
        }
        //查询故障资产
        HashSet<Long> faultAssetIds = new HashSet<>();
        userCanLookFaultList.forEach(item -> faultAssetIds.add(item.getFaultAssetId()));
        List<AsmsFaultDispatchStage> dispatchStages = faultDispatchStageService.list(new QueryWrapper<AsmsFaultDispatchStage>()
                .in(AsmsFaultDispatchStage.FAULT_ASSET_ID, faultAssetIds)
                .eq(AsmsFaultDispatchStage.STATUS, 1).orderByDesc(AsmsFaultDispatchStage.START_TIME));
        for (AsmsFaultDispatchStage dispatchStage : dispatchStages) {
            LineChartVo lineChartVo = new LineChartVo();
            if(dispatchStage.getEndTime()!=null&&dispatchStage.getStartTime()!=null&&dispatchStage.getEndTime() - dispatchStage.getStartTime()>0){
                Long time = (dispatchStage.getEndTime() - dispatchStage.getStartTime());
                lineChartVo.setTitle("故障" + dispatchStage.getFaultAssetId());
                lineChartVo.setValue(time);
                lineChartVos.add(lineChartVo);
            }
        }
        return R.ok(lineChartVos);
    }

    @PreAuthorize
    @ApiOperation("故障处理阶段统计图")
    @GetMapping("/getFaultNumOnResolveStage")
    public R<List<LineChartVo>> getFaultNumOnResolveStage(@RequestParam(value = "startTime", required = false) Long startTime,
                                                          @RequestParam(value = "endTime", required = false) Long endTime) {
        ArrayList<LineChartVo> lineChartVos = new ArrayList<>();
        List<FaultInfoView> userCanLookFaultList = asmsReusingService.getUserCanLookFaultList(startTime, endTime);
        if (userCanLookFaultList.size() == 0) {
            return R.ok(lineChartVos);
        }
        HashSet<Long> faultAssetIds = new HashSet<>();
        userCanLookFaultList.forEach(item -> faultAssetIds.add(item.getFaultAssetId()));
        List<AsmsFaultResolveStage> resolveStages = faultResolveStageService.list(new QueryWrapper<AsmsFaultResolveStage>()
                .in(AsmsFaultResolveStage.FAULT_ASSET_ID, faultAssetIds)
                .eq(AsmsFaultResolveStage.STATUS, 1).orderByDesc(AsmsFaultResolveStage.START_TIME));
        for (AsmsFaultResolveStage resolveStage : resolveStages) {
            LineChartVo lineChartVo = new LineChartVo();
            lineChartVo.setTitle("故障" + resolveStage.getFaultAssetId());
            Long time = (resolveStage.getEndTime() - resolveStage.getStartTime());
            lineChartVo.setValue(time);
            lineChartVos.add(lineChartVo);
        }
        return R.ok(lineChartVos);
    }

    @PreAuthorize
    @ApiOperation("故障确认阶段评分的服务效率分、服务态度分、服务结果分的三个饼图")
    @GetMapping("/getScoreOnConfirmStage")
    public R<ConfirmStagePieListVo> getScoreOnConfirmStage(@RequestParam(value = "startTime", required = false) Long startTime,
                                                           @RequestParam(value = "endTime", required = false) Long endTime) {
        ConfirmStagePieListVo result = new ConfirmStagePieListVo();
        //先获取当前用户能看到的故障资产在确认阶段的数据
        List<FaultInfoView> userCanLookFaultList = asmsReusingService.getUserCanLookFaultList(startTime, endTime);
        if (userCanLookFaultList.size() == 0) {
            return R.ok(result);
        }
        HashSet<Long> faultAssetIds = new HashSet<>();
        userCanLookFaultList.forEach(item -> faultAssetIds.add(item.getFaultAssetId()));
        //构建前端所需的三个饼图数据
        List<PieChartVo> efficiencyScoreList = new ArrayList<>();
        List<PieChartVo> attitudeScoreList = new ArrayList<>();
        List<PieChartVo> qualityScoreList = new ArrayList<>();
        Integer[] score = {1,2,3,4,5};
        for (Integer s : score) {
            //服务效率分
            long count1 = faultConfirmStageService.count(new QueryWrapper<AsmsFaultConfirmStage>()
                    .eq(AsmsFaultConfirmStage.EFFICIENCY_SCORE, s).in(AsmsFaultConfirmStage.FAULT_ASSET_ID, faultAssetIds));
            if (count1 > 0) {
                PieChartVo pieChartVo1 = new PieChartVo();
                pieChartVo1.setType(s + "星");
                pieChartVo1.setValue((int)count1);
                efficiencyScoreList.add(pieChartVo1);
            }
            //服务态度分
            long count2 = faultConfirmStageService.count(new QueryWrapper<AsmsFaultConfirmStage>()
                    .eq(AsmsFaultConfirmStage.ATTITUDE_SCORE, s).in(AsmsFaultConfirmStage.FAULT_ASSET_ID, faultAssetIds));
            if (count2 > 0) {
                PieChartVo pieChartVo2 = new PieChartVo();
                pieChartVo2.setType(s + "星");
                pieChartVo2.setValue((int)count2);
                attitudeScoreList.add(pieChartVo2);
            }
            //服务结果分
            long count3 = faultConfirmStageService.count(new QueryWrapper<AsmsFaultConfirmStage>()
                    .eq(AsmsFaultConfirmStage.QUALITY_SCORE, s).in(AsmsFaultConfirmStage.FAULT_ASSET_ID, faultAssetIds));
            if (count3 > 0) {
                PieChartVo pieChartVo3 = new PieChartVo();
                pieChartVo3.setType(s + "星");
                pieChartVo3.setValue((int)count3);
                qualityScoreList.add(pieChartVo3);
            }
        }
        result.setEfficiencyScoreList(efficiencyScoreList);
        result.setAttitudeScoreList(attitudeScoreList);
        result.setQualityScoreList(qualityScoreList);
        return R.ok(result);
    }

    @PreAuthorize
    @ApiOperation("维护的客户的资产统计图")
    @GetMapping("/getAssetNumWithODept")
    public R<List<HistogramVo>> getAssetNumWithODept(@RequestParam(value = "oDeptId", required = false) Long oDeptId,
                                                     @RequestParam(value = "startTime", required = false) Long startTime,
                                                     @RequestParam(value = "endTime", required = false) Long endTime) {
        List<HistogramVo> histogramVos = new ArrayList<>();
        //获取维护的客户
        Long deptId = tokenService.getLoginUser().getDeptid();
        List<AsmsOwnMaintenanceDept> list = ownMaintenanceDeptService.list(new QueryWrapper<AsmsOwnMaintenanceDept>()
                .eq(AsmsOwnMaintenanceDept.MAINTENANCE_DEPT_ID, deptId));
        if (list.size() == 0) {
            return R.ok(histogramVos);
        }
        HashSet<Long> deptIds = new HashSet<>();
        list.forEach(item -> deptIds.add(item.getOwnDeptId()));
        R<List<SysDept>> oDeptList = deptController.getDeptListByIds(deptIds);
        if (oDeptList.getCode() == R.FAIL) {
            throw new ServiceException(oDeptList.getMsg());
        }
        //只查询属于维护客户的资产,提高遍历的速度
        QueryWrapper<AsmsAssetFullInfo> wrapper = new QueryWrapper<>();
        if (oDeptId != null) {
            wrapper.eq(AsmsAssetFullInfo.OWN_DEPT_ID, oDeptId);
        } else {
            if (deptIds.size() > 0) wrapper.in(AsmsAssetFullInfo.OWN_DEPT_ID, deptIds);
        }
        if (startTime != null && endTime != null) {
            wrapper.ge(AsmsAssetFullInfo.CREATE_TIME, startTime).le(AsmsAssetFullInfo.CREATE_TIME, endTime);
        }
        List<AsmsAssetFullInfo> assetList = assetFullInfoService.list(wrapper);
        if (assetList.size() == 0) {
            return R.ok(histogramVos);
        }
        //计算每个客户对应的资产数量
        for (SysDept sysDept : oDeptList.getData()) {
            int assetNum = 0;
            for (AsmsAssetFullInfo assetFullInfo : assetList) {
                if (assetFullInfo.getOwnDeptId() != null &&
                        assetFullInfo.getOwnDeptId().equals(sysDept.getDeptId())) {
                    assetNum ++;
                }
            }
            if (assetNum > 0) {
                HistogramVo histogramVo = new HistogramVo();
                histogramVo.setParent(sysDept.getDeptShortName());
                histogramVo.setValue(assetNum);
                histogramVos.add(histogramVo);
            }
        }
        histogramVos.sort(Comparator.comparing(HistogramVo::getValue).reversed());
        return R.ok(histogramVos);
    }

    @PreAuthorize
    @ApiOperation("按巡检部门：巡检工单完成情况")
    @GetMapping("/getInspectionTicketsResult")
    public R<List<HistogramVo>> getInspectionTicketsResult(@ApiParam("选中的部门的id") @RequestParam(value = "deptId", required = false) Long deptId,
                                                           @ApiParam("选中的分类对应的整数:全部1、客户2、巡检人员3") @RequestParam(value = "type", required = false) Integer type,
                                                           @RequestParam(value = "startTime", required = false) Long startTime,
                                                           @RequestParam(value = "endTime", required = false) Long endTime) {
        List<HistogramVo> histogramVos = new ArrayList<>();
        if (deptId == null) {
            //没有选择部门就默认展示当前登录用户的部门
            Long sysDeptId = tokenService.getLoginUser().getDeptid();
            QueryWrapper<InspectionTask> wrapper = new QueryWrapper<>();
            wrapper.eq(InspectionTask.MAINTENANCE_DEPT_ID, sysDeptId);
            if (startTime != null && endTime != null) {
                wrapper.ge(InspectionTask.CREATE_TIME, startTime).le(InspectionTask.CREATE_TIME, endTime);
            }
            List<InspectionTask> taskList = inspectionTaskService.list(wrapper);
            R<SysDept> deptR =  deptController.getDeptById(sysDeptId);
            if (deptR.getCode() == R.FAIL) {
                throw new ServiceException(deptR.getMsg());
            }
            //计算已完成的巡检工单数量
            int completeNum = 0; //已完成工单数量
            int notCompleteNum = 0; //未完成工单数量
            for (InspectionTask inspectionTask : taskList) {
                if (inspectionTask.getStatus().equals(3))
                    completeNum ++;
                if (! inspectionTask.getStatus().equals(3))
                    notCompleteNum ++;
            }
            if (completeNum > 0) {
                HistogramVo vo1 = new HistogramVo();
                vo1.setParent(deptR.getData().getDeptShortName());
                vo1.setChild("已完成");
                vo1.setValue(completeNum);
                histogramVos.add(vo1);
            }
            if (notCompleteNum > 0) {
                HistogramVo vo2 = new HistogramVo();
                vo2.setParent(deptR.getData().getDeptShortName());
                vo2.setChild("未完成");
                vo2.setValue(notCompleteNum);
                histogramVos.add(vo2);
            }
        } else {
            //选择了巡检部门和展示类型
            if (type != null) {
                switch (type) {
                    //查看选中的部门以及它的所有下级部门的巡检工单完成情况
                    case 1:
                        R<List<SysDept>> childDept = deptController.getChildDept(deptId);
                        if (childDept.getCode() == R.FAIL) {
                            throw new ServiceException(childDept.getMsg());
                        }
                        HashSet<Long> deptIds = new HashSet<>();
                        childDept.getData().forEach(item -> deptIds.add(item.getDeptId()));
                        QueryWrapper<InspectionTask> wrapper = new QueryWrapper<>();
                        if (deptIds.size() != 0) {
                            wrapper.in(InspectionTask.MAINTENANCE_DEPT_ID, deptIds);
                        }
                        if (startTime != null && endTime != null) {
                            wrapper.ge(InspectionTask.CREATE_TIME, startTime).le(InspectionTask.CREATE_TIME, endTime);
                        }
                        List<InspectionTask> taskList = inspectionTaskService.list(wrapper);
                        if (taskList.size() == 0)
                            return R.ok(histogramVos);
                        //构造柱状图数据
                        for (SysDept sysDept : childDept.getData()) {
                            int completeNum = 0; //已完成工单数量
                            int notCompleteNum = 0; //未完成工单数量
                            for (InspectionTask inspectionTask : taskList) {
                                if (inspectionTask.getMaintenanceDeptId().equals(sysDept.getDeptId())
                                        && inspectionTask.getStatus().equals(3))
                                    completeNum ++;
                                if (inspectionTask.getMaintenanceDeptId().equals(sysDept.getDeptId())
                                        && ! inspectionTask.getStatus().equals(3))
                                    notCompleteNum ++;
                            }
                            if (completeNum > 0) {
                                HistogramVo completeVo = new HistogramVo();
                                completeVo.setParent(sysDept.getDeptShortName());
                                completeVo.setChild("已完成");
                                completeVo.setValue(completeNum);
                                histogramVos.add(completeVo);
                            }
                            if (notCompleteNum > 0) {
                                HistogramVo notCompleteVo = new HistogramVo();
                                notCompleteVo.setParent(sysDept.getDeptShortName());
                                notCompleteVo.setChild("未完成");
                                notCompleteVo.setValue(notCompleteNum);
                                histogramVos.add(notCompleteVo);
                            }
                        }
                        histogramVos.sort(Comparator.comparing(HistogramVo::getValue).reversed());
                        return R.ok(histogramVos);
                    //查看选中的部门的所有巡检客户的工单的完成情况
                    case 2:
                        QueryWrapper<InspectionTask> wrapper1 = new QueryWrapper<>();
                        wrapper1.eq(InspectionTask.MAINTENANCE_DEPT_ID, deptId);
                        if (startTime != null && endTime != null) {
                            wrapper1.ge(InspectionTask.CREATE_TIME, startTime).le(InspectionTask.CREATE_TIME, endTime);
                        }
                        List<InspectionTask> inspectionTasks = inspectionTaskService.list(wrapper1);
                        if (inspectionTasks.size() == 0)
                            return R.ok(histogramVos);
                        HashSet<Long> ownDeptIds = new HashSet<>();
                        for (InspectionTask inspectionTask : inspectionTasks) {
                            String assetOwnIds = inspectionTask.getAssetOwnIds();
                            ownDeptIds.addAll(Arrays.asList(Convert.toLongArray(assetOwnIds)));
                        }
                        //获取到了选中的部门的巡检客户
                        R<List<SysDept>> deptListByIds = deptController.getDeptListByIds(ownDeptIds);
                        if (deptListByIds.getCode() == R.FAIL)
                            throw new ServiceException(deptListByIds.getMsg());
                        if (deptListByIds.getData().size() == 0)
                            return R.ok(histogramVos);
                        //开始构造柱状图数据
                        for (SysDept sysDept : deptListByIds.getData()) {
                            int completeNum = 0; //已完成工单数量
                            int notCompleteNum = 0; //未完成工单数量
                            for (InspectionTask inspectionTask : inspectionTasks) {
                                if (inspectionTask.getAssetOwnIds().contains(sysDept.getDeptId() + "")
                                        && inspectionTask.getStatus().equals(3))
                                    completeNum ++;
                                if (inspectionTask.getAssetOwnIds().contains(sysDept.getDeptId() + "")
                                        && ! inspectionTask.getStatus().equals(3))
                                    notCompleteNum ++;
                            }
                            if (completeNum > 0) {
                                HistogramVo completeVo = new HistogramVo();
                                completeVo.setParent(sysDept.getDeptShortName());
                                completeVo.setChild("已完成");
                                completeVo.setValue(completeNum);
                                histogramVos.add(completeVo);
                            }
                            if (notCompleteNum > 0) {
                                HistogramVo notCompleteVo = new HistogramVo();
                                notCompleteVo.setParent(sysDept.getDeptShortName());
                                notCompleteVo.setChild("未完成");
                                notCompleteVo.setValue(notCompleteNum);
                                histogramVos.add(notCompleteVo);
                            }
                        }
                        histogramVos.sort(Comparator.comparing(HistogramVo::getValue).reversed());
                        return R.ok(histogramVos);
                    //查看选中的部门的所有巡检人员的巡检工单完成情况
                    case 3:
                        R<List<SysUser>> inspectionUsers = userController.getInspectionUsersByDeptId(deptId);
                        if (inspectionUsers.getCode() == R.FAIL)
                            throw new ServiceException(inspectionUsers.getMsg());
                        if (inspectionUsers.getData().size() == 0)
                            return R.ok(histogramVos);
                        QueryWrapper<InspectionTask> wrapper2 = new QueryWrapper<>();
                        wrapper2.eq(InspectionTask.MAINTENANCE_DEPT_ID, deptId);
                        if (startTime != null && endTime != null) {
                            wrapper2.ge(InspectionTask.CREATE_TIME, startTime).le(InspectionTask.CREATE_TIME, endTime);
                        }
                        List<InspectionTask> tasks = inspectionTaskService.list(wrapper2);
                        for (SysUser sysUser : inspectionUsers.getData()) {
                            int completeNum = 0; //已完成工单数量
                            int notCompleteNum = 0; //未完成工单数量
                            for (InspectionTask inspectionTask : tasks) {
                                if (inspectionTask.getInspectionUserIds().contains(sysUser.getUserId() + "")
                                        && inspectionTask.getStatus().equals(3))
                                    completeNum ++;
                                if (inspectionTask.getInspectionUserIds().contains(sysUser.getUserId() + "")
                                        && ! inspectionTask.getStatus().equals(3))
                                    notCompleteNum ++;
                            }
                            if (completeNum > 0) {
                                HistogramVo completeVo = new HistogramVo();
                                completeVo.setParent(sysUser.getNickName());
                                completeVo.setChild("已完成");
                                completeVo.setValue(completeNum);
                                histogramVos.add(completeVo);
                            }
                            if (notCompleteNum > 0) {
                                HistogramVo notCompleteVo = new HistogramVo();
                                notCompleteVo.setParent(sysUser.getNickName());
                                notCompleteVo.setChild("未完成");
                                notCompleteVo.setValue(notCompleteNum);
                                histogramVos.add(notCompleteVo);
                            }
                        }
                        histogramVos.sort(Comparator.comparing(HistogramVo::getValue).reversed());
                        return R.ok(histogramVos);
                }
            }
        }
        histogramVos.sort(Comparator.comparing(HistogramVo::getValue).reversed());
        return R.ok(histogramVos);
    }

    @PreAuthorize
    @ApiOperation("按巡检客户：巡检结果统计饼图")
    @GetMapping("/getInspectionResultByODept")
    public R<List<PieChartVo>> getInspectionResultByODept(@ApiParam("选中的部门的id") @RequestParam(value = "deptId") Long deptId,
                                                          @RequestParam(value = "startTime", required = false) Long startTime,
                                                          @RequestParam(value = "endTime", required = false) Long endTime) {
        ArrayList<PieChartVo> pieChartVos = new ArrayList<>();
        QueryWrapper<Inspection> wrapper = new QueryWrapper<>();
        wrapper.eq(Inspection.OWN_DEPT_ID, deptId);
        if (startTime != null && endTime != null) {
            wrapper.ge(Inspection.CREATE_TIME, startTime).le(Inspection.CREATE_TIME, endTime);
        }
        List<Inspection> inspectionList = inspectionService.list(wrapper);
        ArrayList<ResultTypeVo> resultTypeVos = new ArrayList<>();
        //将所有巡检结果放到集合中
        String[] resultTypeStr = {"正常", "设备故障", "设备漏绑", "安装位置码缺失", "其他"};
        for (int i = 0; i < resultTypeStr.length; i++) {
            ResultTypeVo vo = new ResultTypeVo();
            vo.setKey(i);
            vo.setValue(resultTypeStr[i]);
            resultTypeVos.add(vo);
        }
        for (ResultTypeVo vo : resultTypeVos) {
            int assetNum = 0;
            for (Inspection inspection : inspectionList) {
                if (inspection.getResultType() != null &&
                        inspection.getResultType().equals(vo.getKey()))
                    assetNum ++;
            }
            if (assetNum > 0) {
                PieChartVo pieChartVo = new PieChartVo();
                pieChartVo.setType(vo.getValue());
                pieChartVo.setValue(assetNum);
                pieChartVo.setId(deptId);
                pieChartVos.add(pieChartVo);
            }
        }
        pieChartVos.sort(Comparator.comparing(PieChartVo::getValue).reversed());
        return R.ok(pieChartVos);
    }

    @PreAuthorize
    @ApiOperation("点击某个巡检结果展示详情")
    @PostMapping("/getInspectionResultDetail")
    public TableDataInfo getInspectionResultDetail(@RequestBody InspectionResultDetailVo vo) {
        //获取某个巡检结果类型和巡检客户对应的资产id集合
        List<Inspection> inspectionList = inspectionService.list(new QueryWrapper<Inspection>().eq(Inspection.OWN_DEPT_ID, vo.getDeptId())
                .eq(Inspection.RESULT_TYPE, vo.getResultType()));
        HashSet<Long> assetIds = new HashSet<>();
        inspectionList.forEach(item -> assetIds.add(item.getAssetId()));
        QueryWrapper<AsmsAssetFullInfo> wrapper = new QueryWrapper<>();
        //查询条件
        if (StringUtils.isNotEmpty(vo.getAssetStatus())) {
            wrapper.eq(AsmsAssetFullInfo.ASSET_STATUS, vo.getAssetStatus());
        }
        if (StringUtils.isNotEmpty(vo.getAssetCode())) {
            wrapper.like(AsmsAssetFullInfo.ASSET_CODE, vo.getAssetCode());
        }
        if (StringUtils.isNotEmpty(vo.getAssetTypeName())) {
            wrapper.like(AsmsAssetFullInfo.ASSET_TYPE_NAME, vo.getAssetTypeName());
        }

        if (assetIds.size() != 0) {
            wrapper.in(AsmsAssetFullInfo.ASSET_ID, assetIds);
        } else {
            return getDataTable(new ArrayList<>());
        }
        startPage();
        List<AsmsAssetFullInfo> assetFullInfoList = assetFullInfoService.list(wrapper);
        return getDataTable(assetFullInfoList);
    }

    @PreAuthorize
    @ApiOperation("获取未处理的故障的数量")
    @GetMapping("/getNotResolveFaultNum")
    public AjaxResult getNotResolveFaultNum(@RequestParam(value = "startTime", required = false) Long startTime,
                                            @RequestParam(value = "endTime", required = false) Long endTime) {
        Long deptId = tokenService.getLoginUser().getDeptid();
        QueryWrapper<AsmsFaultAsset> wrapper = new QueryWrapper<>();
        wrapper.eq(AsmsFaultAsset.MAINTENANCE_DEPT_ID, deptId).eq(AsmsFaultAsset.IS_FINISH, 1);
        if (startTime != null && endTime != null) {
            wrapper.ge(AsmsFaultAsset.CREATE_TIME, startTime).le(AsmsFaultAsset.CREATE_TIME, endTime);
        }
        long count = asmsFaultAssetService.count(wrapper);
        return AjaxResult.success(count);
    }

    @PreAuthorize
    @ApiOperation("将故障数量与地图数据一起返回")
    @GetMapping("/getFaultNumWithMap")
    public R<List<FaultNumAndMapVo>> getFaultNumWithMap(@RequestParam(value = "startTime", required = false) Long startTime,
                                                        @RequestParam(value = "endTime", required = false) Long endTime) {
        List<FaultNumAndMapVo> resultList = new ArrayList<>();
        //获取当前用户可见的故障列表
        List<FaultInfoView> userCanLookFaultList = asmsReusingService.getUserCanLookFaultList(startTime, endTime);
        if (userCanLookFaultList.size() == 0) {
            return R.ok(resultList);
        }
        //构造部门与故障数的对应关系
        HashSet<Long> ownDeptIds = new HashSet<>();
        userCanLookFaultList.forEach(item -> ownDeptIds.add(item.getOwnDeptId()));
        HashMap<Long, Integer> ownDeptIdFaultNumMap = new HashMap<>();
        ownDeptIds.forEach(ownDeptId -> {
            int faultNum = 0;
            for (FaultInfoView infoView : userCanLookFaultList) {
                if (infoView.getOwnDeptId() != null &&
                        infoView.getOwnDeptId().equals(ownDeptId)) {
                    faultNum++;
                }
            }
            ownDeptIdFaultNumMap.put(ownDeptId, faultNum);
        });
        //构造区域与故障数的对应关系
        HashSet<Long> geoIds = new HashSet<>();
        R<List<SysDept>> depts = deptController.getDeptListByIds(ownDeptIds);
        if (depts.getCode() == R.FAIL) {
            throw new ServiceException(depts.getMsg());
        }
        depts.getData().forEach(dept -> geoIds.add(dept.getGeographicalId()));
        HashMap<Long, Integer> geoIdFaultNumMap = new HashMap<>();
        geoIds.forEach(geoId -> {
            int faultNum = 0;
            for (SysDept sysDept : depts.getData()) {
                if (sysDept.getGeographicalId() != null && sysDept.getGeographicalId().equals(geoId)) {
                    faultNum += ownDeptIdFaultNumMap.get(sysDept.getDeptId());
                }
            }
            geoIdFaultNumMap.put(geoId, faultNum);
        });
        //获取所有的区域地址
        R<List<SysGeographical>> geographicals = geographicalController.getGeographicals();
        if (geographicals.getCode() == R.FAIL) {
            throw new ServiceException(geographicals.getMsg());
        }
        List<SysGeographical> geographicalList = geographicals.getData();
        geographicalList.forEach(geo -> {
            FaultNumAndMapVo vo = new FaultNumAndMapVo();
            BeanUtils.copyProperties(geo, vo);
            vo.setName(geo.getGeographicalName());
            vo.setAdcode(Integer.valueOf(geo.getGeographicalCode()));
            Integer faultNum = geoIdFaultNumMap.get(geo.getGeographicalId());
            vo.setFaultNum(faultNum != null ? faultNum : 0);
            resultList.add(vo);
        });
        return R.ok(resultList);
    }

    /*******************************数据大屏统计接口*****************************/

    @ApiOperation("累计维护资产数量：公司查看")
    @GetMapping("/mAssetNumLookByCompany")
    public AjaxResult mAssetNumLookByCompany() {
        return AjaxResult.success(asmsDataStatisticsService.mAssetNum());
    }

    @ApiOperation("累计故障处理数量：公司查看")
    @GetMapping("/solveFaultNumLookByCompany")
    public AjaxResult solveFaultNumLookByCompany() {
        return AjaxResult.success(asmsDataStatisticsService.solveFaultNum());
    }

    @ApiOperation("累计巡检数量：公司查看")
    @GetMapping("/inspectionNumLookByCompany")
    public AjaxResult inspectionNumLookByCompany() {
        return AjaxResult.success(asmsDataStatisticsService.inspectionNum());
    }

    @ApiOperation("今日故障情况：公司查看")
    @GetMapping("/todayFaultLookByCompany")
    public AjaxResult todayFaultLookByCompany() {
        return AjaxResult.success(asmsDataStatisticsService.todayFaultNum());
    }

    @ApiOperation("今日巡检情况：公司查看")
    @GetMapping("/todayInspectionLookByCompany")
    public AjaxResult todayInspectionLookByCompany() {
        return AjaxResult.success(asmsDataStatisticsService.todayInspectionNum());
    }

    @ApiOperation("今日绑定的资产数量：公司查看")
    @GetMapping("/todayBindAssetLookByCompany")
    public AjaxResult todayBindAssetLookByCompany() {
        return AjaxResult.success(asmsDataStatisticsService.todayBindAssetNum());
    }

    @ApiOperation("本周资产运维情况：公司查看")
    @GetMapping("/thisWeekFaultLookByCompany")
    public R<List<List<ThisWeekFaultVo>>> thisWeekFaultLookByCompany(
            @ApiParam("查看故障：0， 查看巡检：1") @RequestParam("faultOrInsp") Integer faultOrInsp) {
        return R.ok(asmsDataStatisticsService.thisWeekFault(faultOrInsp));
    }

    @ApiOperation("当月故障维护情况：公司查看")
    @GetMapping("/thisMonthFaultLookByCompany")
    public R<ThisMonthFaultVo> thisMonthFaultLookByCompany() {
        return R.ok(asmsDataStatisticsService.thisMonthFault());
    }

    @ApiOperation("当月学校巡检情况：公司查看")
    @GetMapping("/thisMonthInspectionLookByCompany")
    public R<ThisMonthInspectionVo> thisMonthInspectionLookByCompany() {
        return R.ok(asmsDataStatisticsService.thisMonthInspection());
    }

}
